﻿using BUS;
using DTO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLBV_Nhom8
{
    public partial class frmThanhToanKhamBenh : Form
    {
        public frmThanhToanKhamBenh()
        {
            InitializeComponent();
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtMaPhieuKham.Text))
            {
                string ma = txtMaPhieuKham.Text;
                if (ma.StartsWith("PKB"))
                    ma = ma.Replace("PKB", "");

                string sql = @"select ChiTietToaThuoc.MaTT, TenThuoc, SoLuong, GiaTien, CongDung, CachDung, MaPKB from ToaThuoc, ChiTietToaThuoc, Thuoc where Thuoc.MaThuoc = ChiTietToaThuoc.MaThuoc 
                        and ToaThuoc.MaTT = ChiTietToaThuoc.MaTT and MaPKB = " + ma;
                dataGridView1.DataSource = ChiTietToaThuocBUS.LayDanhSachChiTietToaThuocTheoMaPKB(sql);


                dataGridView1.Columns[0].Visible = false;
                dataGridView1.Columns[6].Visible = false;

                double tong = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    tong += Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value) * Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);
                }

                txtTongTien.Text = tong.ToString();
            }
            else
            {
                MessageBox.Show("Nhập Mã Phiếu Khám Bệnh");
            }
        }
    }
}
